import type { BaseEntity, ID, PageQuery, PageResult } from '#/api/common';

import { requestClient } from '#/api/request';

export interface DictData {
  value: string;
  label: string;
  tableCls: string;
}

export interface SysDict extends BaseEntity {
  dictId: ID;
  dictName: string;
  dictKey: string;
  dictValue: DictData[];
  remark: string;
}

const baseUrl = `/sys_biz/sys_dict`;

// 查询字典列表
export function listDict(query: PageQuery) {
  return requestClient.get<PageResult<SysDict>>(`${baseUrl}/list`, {
    params: query,
  });
}

// 查询字典详细
export function getDict(dictId: ID) {
  return requestClient.get<SysDict>(`${baseUrl}/${dictId}`);
}

// 新增字典配置
export function addDict(data: any) {
  return requestClient.post(`${baseUrl}/add`, data);
}

// 修改字典配置
export function editDict(data: any) {
  return requestClient.post(`${baseUrl}/edit`, data);
}

// 删除字典配置
export function delDict(dictId: ID) {
  return requestClient.post(`${baseUrl}/remove`, dictId);
}

// 刷新字典缓存
export function refreshCache() {
  return requestClient.post(`${baseUrl}/refresh_cache`);
}
